package com.da.javatest.niuke.baodian;

/**
 * @author chenlida
 * @date 2020/10/9 16:17
 * https://www.nowcoder.com/practice/e8bb8e68434e42acbcdff0341f2a32c5?tpId=8&tags=&title=&diffculty=0&judgeStatus=0&rp=1
 */
public class C40Robot {
    public static int countWays(int x, int y) {
        if (x == 1 || y == 1) {
            return 1;
        }
        return countWays(x - 1, y) + countWays(x, y - 1);
    }

    public static void main(String[] args) {
        System.out.println(countWays(3, 3));
        System.out.println(countWays2(3, 3));
    }

    /**
     * 动态规划的方式
     */
    public static int countWays2(int x, int y) {
        int[][] dp = new int[x][y];
        for (int i = 0; i < x; i++) {
            dp[i][0] = 1;
        }
        for (int j = 0; j < y; j++) {
            dp[0][j] = 1;
        }
        for (int i = 1; i < x; i++) {
            for (int j = 1; j < y; j++) {
                dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
            }
        }

        return dp[x - 1][y - 1];
    }
}
